<!-- 本页面是系统socket页面
          使用方法 :在需要支持websocket消息推送的页面直接引入该页面，<-%@include file=".../common/systemInfoSocket-init.jsp->
              :在本页面需要配置wsServer.
-->
<%@ page contentType="text/html;charset=UTF-8" %>
<script src="${ctxStatic}/plugin/layui/sockjs.js"></script><!-- 如果浏览器不支持socktjs，添加支持 -->
<script type="text/javascript">
(function() {
        var host = window.document.location.host;
        var pathName = window.document.location.pathname;
        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
        var wsServer = "ws://" + host + projectName;

		var webSocket = null;
		if ('WebSocket' in window || 'MozWebSocket' in window) {
			  webSocket = new WebSocket(wsServer+"/systemInfoSocketServer");
		  } else {
			  webSocket = new SockJS( wsServer+"/sockjs/systemInfoSocketServer");
		  }

		  webSocket.onerror = function(event) {
		    jp.alert("websockt连接发生错误，请刷新页面重试!")
		  };

		// 接收到消息的回调方法
		  webSocket.onmessage = function(event) {
		    var res=event.data;
		    console.log(res);
		    if(res.indexOf("dbMsg") > -1){
                var msg = res.split(";");
                var json = $.parseJSON(msg[1]);
                //待办总条数count
                //待办条数dbCount
                //未审阅抄送csCount
                $("#count").html(json.count);
                $("#dbCount").html("您有 " + json.dbCount + " 条待办流程");
                $("#csCount").html("您有 " + json.csCount + " 条待审阅抄送");
               /* jp.toastr.info(res,"系统通知")
                jp.voice();*/
                // jp.toastr.info("您的待办已更新！","系统通知")
            }
              // if(res.indexOf("initMsg") > -1){
              //     var msg = res.split(";");
              //     var json = $.parseJSON(msg[1]);
              //     //待办总条数count
              //     //待办条数dbCount
              //     //未审阅抄送csCount
              //     if(json.count != 0){
              //         jp.toastr.info("您有未处理的待办！","系统通知")
              //     }else {
              //         setTimeout(function () {
              //             jp.toastr.info("您有未处理的待办11111！","系统通知")
              //         },5000)
              //     }
              // }
		  };
})(jQuery);
</script>
